<template>
  <mi-header></mi-header>
  <div class="order">
    <!-- 我的订单头部 -->
    <div class="order-header">
      <div class="order-header-content">
        <p>
          <i class="el-icon-s-order" style="font-size: 30px;color: #ff6700;"></i>
          我的订单
        </p>
        <form id="orderDetailSearchForm" action="" method="get" class="search-form clearfix">
          <input type="search" id="search" name="keyword" autocomplete="off" class="search-text" v-model="keyword">
          <el-button type="primary"
                     icon="el-icon-search"
                     class="search-btn"
                     v-on:click="searchOrderList"></el-button>
        </form>
      </div>
    </div>
    <!-- 我的订单头部END -->

    <!-- 我的订单主要内容 -->
    <div class="order-content" v-if="orders.length>0">
      <div class="content" v-for="(item,index) in orders" :key="index">
        <ul>
          <!-- 我的订单表头 -->
          <li class="order-info">
            <div class="order-id">
              <router-link
                :to="{ name: 'order-detail', params: {orderId:item.orderId} }"
              >订单单号: {{item.orderId}}</router-link>
            </div>
            <div class="order-time">创建时间: {{item.orderTime}}</div>
            <div class="order-status">订单状态: {{item.status}}</div>
          </li>
          <li class="header">
            <div class="pro-img"></div>
            <div class="pro-name">商品名称</div>
            <div class="pro-price">单价</div>
            <div class="pro-num">数量</div>
            <div class="pro-total">小计</div>
          </li>
          <!-- 我的订单表头END -->

          <!-- 订单列表 -->
          <li class="product-list" v-for="(product,i) in item.goods" :key="i">
            <div class="pro-img">
              <router-link :to="{ name: 'product', params: {productId:product.productId} }">
                <img :src="product.pic_urls" />
              </router-link>
            </div>
            <div class="pro-name">
              <router-link
                :to="{ name: 'product', params: {productId:product.productId} }"
              >{{product.productName}}</router-link>
            </div>
            <div class="pro-price">{{product.productPrice}}元</div>
            <div class="pro-num">{{product.productNum}}</div>
            <div class="pro-total pro-total-in">{{product.productPrice*product.productNum}}元</div>
          </li>
        </ul>
        <div class="order-bar">
          <div class="order-bar-left">
            <span class="order-total">
              共
              <span class="order-total-num">{{item.totalNum}}</span> 件商品
            </span>
          </div>
          <div class="order-bar-right">
            <span>
              <span class="total-price-title">合计：</span>
              <span class="total-price">{{item.payPrice}}元</span>
            </span>
          </div>
          <!-- 订单列表END -->
        </div>
      </div>
      <div style="margin-top:-40px;"></div>
    </div>
    <!-- 我的订单主要内容END -->

    <!-- 订单为空的时候显示的内容 -->
    <div v-else class="order-empty">
      <div class="empty">
        <h2>您的订单还是空的！</h2>
        <p>快去购物吧！</p>
      </div>
    </div>
    <!-- 订单为空的时候显示的内容END -->
  </div>
  <mi-footer></mi-footer>
</template>

<script>
import MiFooter from '@/components/MiFooter'
import MiHeader from '@/components/MiHeader'
import axios from 'axios'

export default {
  name: 'OrderList',
  components: {
    MiFooter,
    MiHeader
  },
  data () {
    return {
      keyword: '',
      orders: [
        {
          id: 8508,
          orderId: '64081644567014730',
          orderTime: '2022-02-16 00:00:00',
          status: '已完成',
          payPrice: '5198',
          totalNum: '2',
          goods: [
            {
              productId: 129,
              productName: 'mi6',
              productNum: 2,
              pic_urls: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1621955784.84614979.jpg',
              productPrice: 2599
            }
          ],
          userId: 6408
        },
        {
          id: 9507,
          orderId: '64081644567019507',
          orderTime: '2022-02-14 00:00:00',
          status: '已完成',
          payPrice: '14396',
          totalNum: '4',
          goods: [
            {
              productId: 1,
              productName: 'Redmi K30',
              productNum: 2,
              pic_urls: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1621955784.84614979.jpg',
              productPrice: 1599
            },
            {
              productId: 12,
              productName: 'iphone13',
              productNum: 2,
              pic_urls: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1621955784.84614979.jpg',
              productPrice: 5599
            }
          ],
          userId: 6408
        }
      ] // 订单列表
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    getOrderList () {
      // 获取订单数据
      axios.get('http://localhost:8088/order/getOrderList',
        {
          params: {
            userId: 123
          }
        }).then(res => {
        if (res.data.code === '0') {
          this.orders = res.data.data
        } else {
          alert(res.data.msg)
        }
      })
    },
    searchOrderList () {
      if (!this.keyword || this.keyword === '') {
        this.getOrderList()
        return
      }
      // 获取订单数据
      axios.get('http://localhost:8088/order/search',
        {
          params: {
            keyword: this.keyword
          }
        }).then(res => {
        if (res.data.code === '0') {
          this.orders = res.data.data
        } else {
          alert(res.data.msg)
        }
      })
    }
  }
}
</script>

<style>
  * {
    list-style: none;
  }
  .order {
    background-color: #f5f5f5;
    padding-bottom: 20px;
  }
  /* 我的订单头部CSS */
  .order .order-header {
    height: 64px;
    border-bottom: 2px solid #ff6700;
    background-color: #fff;
    margin-bottom: 20px;
  }
  .order .order-header .order-header-content {
    width: 1225px;
    margin: 0 auto;
  }
  .order .order-header p {
    font-size: 28px;
    line-height: 58px;
    float: left;
    font-weight: normal;
    color: #424242;
  }
  /* 我的订单头部CSS END */
  .order .content {
    width: 1225px;
    margin: 0 auto;
    background-color: #fff;
    margin-bottom: 50px;
  }

  .order .content ul {
    background-color: #fff;
    color: #424242;
    line-height: 85px;
  }
  /* 我的订单表头CSS */
  .order .content ul .order-info {
    height: 60px;
    line-height: 60px;
    padding: 0 26px;
    color: #424242;
    border-bottom: 1px solid #ff6700;
  }
  .order .content ul .order-info .order-id {
    float: left;
    color: #ff6700;
  }
  .order .content ul .order-info .order-time {
    float: right;
  }
  .order .content ul .order-info .order-status {
    float: right;
    margin-right: 40px;
  }

  .order .content ul .header {
    height: 85px;
    padding-right: 26px;
    color: #424242;
  }
  /* 我的订单表头CSS END */

  /* 订单列表CSS */
  .order .content ul .product-list {
    height: 85px;
    padding: 15px 26px 15px 0;
    border-top: 1px solid #e0e0e0;
  }
  .order .content ul .pro-img {
    float: left;
    height: 85px;
    width: 120px;
    padding-left: 80px;
  }
  .order .content ul .pro-img img {
    height: 80px;
    width: 80px;
  }
  .order .content ul .pro-name {
    float: left;
    width: 380px;
  }
  .order .content ul .pro-name a {
    color: #424242;
  }
  .order .content ul .pro-name a:hover {
    color: #ff6700;
  }
  .order .content ul .pro-price {
    float: left;
    width: 160px;
    padding-right: 18px;
    text-align: center;
  }
  .order .content ul .pro-num {
    float: left;
    width: 190px;
    text-align: center;
  }
  .order .content ul .pro-total {
    float: left;
    width: 160px;
    padding-right: 81px;
    text-align: right;
  }
  .order .content ul .pro-total-in {
    color: #ff6700;
  }

  .order .order-bar {
    width: 1185px;
    padding: 0 20px;
    border-top: 1px solid #ff6700;
    height: 50px;
    line-height: 50px;
    background-color: #fff;
  }
  .order .order-bar .order-bar-left {
    float: left;
  }
  .order .order-bar .order-bar-left .order-total {
    color: #757575;
  }
  .order .order-bar .order-bar-left .order-total-num {
    color: #ff6700;
  }
  .order .order-bar .order-bar-right {
    float: right;
  }
  .order .order-bar .order-bar-right .total-price-title {
    color: #ff6700;
    font-size: 14px;
  }
  .order .order-bar .order-bar-right .total-price {
    color: #ff6700;
    font-size: 30px;
  }
  /* 订单列表CSS END */

  /* 订单为空的时候显示的内容CSS */
  .order .order-empty {
    width: 1225px;
    margin: 0 auto;
  }
  .order .order-empty .empty {
    height: 300px;
    padding: 0 0 130px 558px;
    margin: 65px 0 0;
    background: url(../../imgs/cart-empty.png) no-repeat 124px 0;
    color: #b0b0b0;
    overflow: hidden;
  }
  .order .order-empty .empty h2 {
    margin: 70px 0 15px;
    font-size: 36px;
  }
  .order .order-empty .empty p {
    margin: 0 0 20px;
    font-size: 20px;
  }
  /* 订单为空的时候显示的内容CSS END */
  #orderDetailSearchForm{
    float: right;
    position: relative;
    width: 296px;
    height: 50px;
    z-index: 20;
  }
  .search-text {
    right: 51px;
    z-index: 1;
    width: 223px;
    height: 48px;
    padding: 0 10px;
    font-size: 14px;
    line-height: 48px;
  }
  .search-btn {
    right: 0;
    z-index: 2;
    width: 52px;
    height: 50px;
    font-size: 24px;
    line-height: 24px;
    background: #fff;
    color: #616161;
    position: absolute;
    top: 0;
    border: 1px solid #e0e0e0;
    outline: 0;
    transition: all 0.2s;
  }
</style>
